<%@ page language="java" contentType="text/html; charset=utf-8"
	pageEncoding="utf-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<%@ taglib prefix="shiro" uri="http://shiro.apache.org/tags"%>
<%@ taglib uri="token-tag" prefix="t"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<jsp:include page="/common/commonCss.jsp"></jsp:include>
<jsp:include page="/common/commonJs.jsp"></jsp:include>
<script type="text/javascript"
	src="${basePath }commonJs/quinn_commons.js"></script>

<script type="text/javascript">
	$(document).ready(function() {
	});

	function blockTr(id) {
		$("#tr_" + id).show();
	}

	function jia(id, count) {
		var v = $("#" + id).val();
		var no = getRetOrderPrdCount(id);
		if ((parseInt(v) - no) <= -count) {
			alertInfo("数量已达上限");
			return;
		}
		$("#" + id).val((parseInt(v) - 1));
		countPrice();
	}
	
	function valid(o,count){
		var v = $(o).val();
		var _v = parseInt(v);
		if(_v>0){
				alertInfo("退货数量只能为负数");
				$(o).val(0);
				countPrice();
				return;
		}
		var no = getRetOrderPrdCount(id);
		if ((parseInt(_v) - no) <= -count) {
			alertInfo("数量已达上限");
			$(o).val(0);
			countPrice();
			return;
		}
		countPrice();
	}

	function jian(id, count) {
		var v = $("#" + id).val();
		if (parseInt(v) < 0) {
			$("#" + id).val((parseInt(v) + 1));
			countPrice();
		}

	}

	function getRetOrderPrdCount(id) {
		var c = 0;
		$.ajax({
			url : "${basePath}ret/getRetOrderPrdCount.shtml",
			type : "post",
			dataType : "json",
			data : {
				pid : id,
				oid : "${order.pkOrderId }"
			},
			async : false,
			success : function(data) {
				c = data;
			},
			error : function(XMLHttpRequest) {
				ajaxError(XMLHttpRequest);
			}
		});
		return c;
	}

	function countPrice() {
		var ytje = 0;
		$("#table1 tr[id*='tr']").each(function() {
			var txt = $(this).find("input:text");
			var no = txt.val();
			var id = txt.attr("id");
			var dj = $("#dj_" + id).html();
			var xj = parseFloat(dj) * parseInt(no);
			$("#xj_" + id).html(xj);
			ytje += xj;
		});
		$("#ytje").html(ytje);
	}

	function ret() {
		$.messager.confirm("提示", "确定要提交吗?", function(d) {
			var prds = [];
			var cont = false;
			$("#table1 tr[id*='tr']").each(function() {
				var text = $(this).find("input:text");
				var id = text.attr("id");
				var v = text.val();
				var prd = id;
				if (parseInt(v) < 0) {
					cont = true;
				}
				prd += "_" + v;
				prd += "_" + $("#xj_" + id).html();
				prds.push(prd);
			});
			if (!cont) {
				alertError("请至少选择一个退货的商品");
				return;
			}
			$("#h_amount").val($("#ytje").html());
			$("#h_prds").val(prds.toString());
			document.forms[0].submit();
		});
	}
</script>
<style>
#show {
	display: none;
}
</style>
<title>首页</title>
</head>
<body class="bg">

	<form action="${basePath }ret/add.shtml" method="post">
		<t:token />
		<input type="hidden" name="fkOriorderId" id="fkOriorderId"
			value="${order.pkOrderId }"> <input type="hidden"
			name="amount" id="h_amount"> <input type="hidden" name="prds"
			id="h_prds">
	</form>

	<div class="content m_auto">
		<div class="content_l mt10">
			<ul>
				<shiro:hasPermission name="payment/skmx.shtml">
					<li class="content_hover"><a
						href="${basePath }payment/skmx.shtml"><i class="nav_icon_k"></i><br>收款</a></li>
				</shiro:hasPermission>
				<shiro:hasPermission name="payment/symx.shtml">
					<li><a href="${basePath }payment/symx.shtml"><i
							class="nav_icon_l"></i><br>收银明细</a></li>
				</shiro:hasPermission>
			</ul>
		</div>
		<div class="content_r mt10">
			<div class="p20">
				<h1 class="f16">订单信息</h1>
				<div class="goods_order_top fixed mt10 f14">
					<ul class="ml10">
						<li><label>订单号：</label>${order.pkOrderId }</li>
						<li><label>当前操作人：</label>${loginUser.name }</li>

						<li>嘉童KerryKidz 天津店</li>
					</ul>
				</div>
				<table class="table mt10" id="table1">
					<tr>
						<th>序号</th>
						<th>商品编号</th>
						<th>商品名称</th>
						<th width="150">数量</th>
						<th>单价</th>
						<th>小计</th>
						<th>折扣率</th>
						<th>备注</th>
						<th>折后金额</th>
						<th>操作</th>
					</tr>
					<c:forEach items="${products }" var="p" varStatus="vs">
						<tr>
							<td>${vs.index+1 }</td>
							<td>${p.fkPrdId }</td>
							<td>${p.productName }</td>
							<td>${p.count }</td>
							<td>￥${p.price }</td>
							<td>￥${p.price*p.count }</td>
							<td>${p.disValue }</td>
							<td>${p.discComments }</td>
							<td>￥${p.disPrice }</td>
							<td><c:if
									test="${p.cateType != '1' && p.cateType != '2' and p.cateType != '3' and p.cateType != '4' and p.cateType != '7' and p.cateType != '8' and p.cateType != '9' and p.cateType != '10' and p.cateType != '20'}">
									<input type="button" value="退货" class="btn_l"
										onclick="blockTr('${p.fkPrdId}')">
								</c:if></td>
						</tr>
					</c:forEach>
					<c:forEach items="${products }" var="p" varStatus="vs">
						<c:if
							test="${p.cateType != '1' && p.cateType != '2' and p.cateType != '3' and p.cateType != '4' and p.cateType != '7' and p.cateType != '8' and p.cateType != '9' and p.cateType != '10' and p.cateType != '20'}">
							<tr style="display: none;" id="tr_${p.fkPrdId }">
								<td></td>
								<td>${p.fkPrdId }</td>
								<td>${p.productName }</td>
								<td class="color_org"><a
									href="javascript:jian('${p.fkPrdId }',${p.count })"
									class="jia_icon"></a> <input type="text" value="0"
									class="iput_t w50" id="${p.fkPrdId }"
									onblur="valid(this,${p.count })"> <a
									href="javascript:jia('${p.fkPrdId }',${p.count })"
									class="jian_icon"></a></td>
								<td>￥<span id="dj_${p.fkPrdId }">${p.price }</span></td>
								<td class="color_org">￥<span id="xj_${p.fkPrdId }">0</span></td>
								<td></td>
								<td class="color_org"></td>
								<td></td>
								<td></td>
							</tr>
						</c:if>
					</c:forEach>
					<tr>
						<td colspan="10">
							<ul class="goods_ul fr p10">
								<li>商品总价：<span class="color_lv mlr5 f18">￥${order.amount }</span></li>
								<li>应退金额<span class="fb mlr5 color_org f18">￥<span
										id="ytje">0</span></span></li>
							</ul>
						</td>
					</tr>
				</table>
				<div class="fr mt10 fixed">
					<input type="button" class="btn ml10" value="确认" onClick="ret();">
					<input type="button" class="btn ml10" value="返回" onClick="window.location.href='${basePath}payment/skmx.shtml'">
				</div>
				<div class="clear"></div>
				<table class="table mt10">
					<tr>
						<th>操作人</th>
						<th>操作时间</th>
						<th>收银金额</th>
						<th>收银方式</th>
						<th>对应订单号</th>
						<th>操作描述</th>
					</tr>

					<c:forEach items="${records }" var="p">
						<tr>
							<td>${p.operator }</td>
							<td><fmt:formatDate value="${p.opeTime }" /></td>
							<td class=" color_org">￥${p.price }</td>
							<td><c:choose>
									<c:when test="${p.payMethod eq '1' }">
											现金
									</c:when>
									<c:when test="${p.payMethod eq '2' }">
											储值消费
									</c:when>
									<c:when test="${p.payMethod eq '3' }">
											银行卡
									</c:when>
								</c:choose></td>
							<td class="lv">${p.id }</td>
							<td>${p.opeDesc }</td>
						</tr>
					</c:forEach>

				</table>
			</div>
		</div>
	</div>






	<!---弹出层--->
	<div id="e" class="easyui-window" title="特殊折扣设置"
		data-options="modal:true,closed:true,iconCls:'icon-save'"
		style="width: 500px; height: 300px; position: relative;">
		<div class="margin_auto w300 pt30">
			<ul class="ul_label f14">
				<li><label>折扣率：</label><input type="text" class="iput_t"></li>
				<li><label>经理密码：</label><input type="text" class="iput_t"></li>
			</ul>
		</div>
		<div class="btm_btn btm_bg">
			<dl>
				<dd>
					<input type="button" class="btn" onclick="javascript:alert('ok')"
						value="确定">
				</dd>
				<dd>
					<input type="button" class="btn" onclick="javascript:alert('ok')"
						value="取消">
				</dd>
			</dl>
		</div>
	</div>
</body>
</html>